import { UserEntity } from './user.entity';

import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';

@Entity('message')
export class MessageEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => UserEntity, user => user.messages)
  @JoinColumn()
  owner?: UserEntity;

  @CreateDateColumn({
    name: 'create_time',
    type: 'timestamp',
  })
  createTime: Date;

  @Column()
  title: string;

  @Column({
    type: 'text',
  })
  content: string;

  constructor(owner: UserEntity, title: string, content: string) {
    this.owner = owner;
    this.title = title;
    this.content = content;
  }
}
